package ${package.Controller};

import com.win.dfas.common.vo.WinResponseData;
import ${package.Service}.${table.serviceName};
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import ${cfg.package}.vo.query.${entity}QryVO;
import ${cfg.package}.vo.request.${entity}ReqVO;
import ${cfg.package}.vo.response.${entity}RepVO;


import java.util.List;
import com.github.pagehelper.PageInfo;
import com.win.dfas.common.validation.ValidationGroup;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@Api(tags = "${table.comment!} 前端控制器")
@RestController
@RequestMapping("/${cfg.request_path!}")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${entity?uncap_first}Service;

    /**
     * ${table.comment!}  详情查询
     *
     * @param id 主键
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "详情查询")
    @GetMapping("/get")
    WinResponseData<${entity}RepVO> get(@ApiParam(value = "id", required = true) @RequestParam("id") long id){
        return WinResponseData.handleSuccess(${entity?uncap_first}Service.get(id));
    }

    /**
     * ${table.comment!}  列表查询
     *
     * @param qryVO 查询条件
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "列表查询")
    @PostMapping("/list")
    public WinResponseData<List<${entity}RepVO>> list(@ApiParam(value="查询参数") @Validated(ValidationGroup.Query.class) @RequestBody ${entity}QryVO qryVO){
        return WinResponseData.handleSuccess(${entity?uncap_first}Service.list(qryVO));
    }

    /**
     * ${table.comment!}  分页列表查询
     *
     * @param qryVO 查询条件
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "分页列表查询")
    @PostMapping("/pageList")
    public WinResponseData<PageInfo<${entity}RepVO>> pageList(@ApiParam(value="查询参数") @Validated(ValidationGroup.PageQuery.class) @RequestBody ${entity}QryVO qryVO){
        return WinResponseData.handleSuccess(${entity?uncap_first}Service.pageList(qryVO));
    }

    /**
     * ${table.comment!}  新增
     *
     * @param reqVO 请求参数
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "新增")
    @PostMapping("/save")
    WinResponseData<String> save(@ApiParam(value="新增参数") @Validated(ValidationGroup.Add.class) @RequestBody ${entity}ReqVO reqVO){
         ${entity?uncap_first}Service.save(reqVO);
         return WinResponseData.handleSuccess("新增成功");
    }

    /**
     * ${table.comment!}  修改
     *
     * @param reqVO 请求参数
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "修改")
    @PutMapping("/update")
    WinResponseData<String> update(@ApiParam(value="修改参数") @Validated(ValidationGroup.Update.class) @RequestBody ${entity}ReqVO reqVO){
        ${entity?uncap_first}Service.update(reqVO);
        return WinResponseData.handleSuccess("修改成功");
    }

    /**
     * ${table.comment!}  删除
     *
     * @param id 主键
     * @return com.win.dfas.common.vo.WinResponseData
     * @author ${author}
     * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
     */
    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    WinResponseData<String> delete(@ApiParam(value = "删除参数") @RequestBody List<String> ids){
        // TODO 选着对应的表名常量
        // commonService.batchDeleteByIds(ids, TableNameConst.RIVAL_INFO);
        return WinResponseData.handleSuccess("删除成功");
    }
}
